<!DOCTYPE html>
<html>

<head>
  <title> new document </title>
  <meta charset="utf-8">
  <script src="js/jquery-1.11.3.js"></script>
</head>

<body>
  <h1>操作元素的属性</h1>
  <img src="img/1.jpg" alt="1">
  <script>
    //单击图片，切换下一张
    $("img").click(function () {
      var $alt = parseInt($(this).attr("alt"));
      var $scr = $(this).attr("src");
      // if ($alt < 4) {
      //    $alt++;
      // } else {
      //    $alt = 1;
      // }
      $alt < 4 ? ($alt++) : ($alt = 1);
      $(this).attr("src", `img/${$alt}.jpg`)
      $(this).attr("alt", $alt);

    });
  </script>
</body>

</html>